package com.jt.controller;

import com.jt.pojo.User;
import com.jt.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@CrossOrigin
@RequestMapping("/axios")
public class UserController {
    @Autowired
    private UserService userService;
    @RequestMapping("/findAll")
    public List<User> findAll(){

        return userService.findAll();
    }
    @RequestMapping("/findById")
    public User findById(Integer id){
        return userService.findById(id);
    }

    @RequestMapping("/findUserByAS")
    public List<User> findUserByAS(User user){
        return userService.findUserByAS(user);
    }
//    @RequestMapping(value = "/updateById/{id}/{name}/{age}/{sex}",
//    method = RequestMethod.PUT)
    @PutMapping("/updateById")
    public String updateById(@RequestBody User user){
        userService.updateById(user);
        return "成功";
    }
    @RequestMapping("/findUserByLike")
    public List<User> findUserByLike(String name){
        return userService.findUserByLike(name);
    }
    @RequestMapping("/findUserByIds")
    public List<User> findUserByIds(Integer[] ids){
        return userService.findUserByIds(ids);
    }
    @PostMapping("/saveUser")
    public String saveUser(@RequestBody User user){
        userService.saveUser(user);
        return "成功";
    }
    @DeleteMapping("/deleteUser")
    public String deleteUser(User user){
        userService.deleteUser(user);
        return "删除成功！";
    }
}
